<h3>Listing timeslots</h3>

<table>
  <tr>
		<th>Date</th>
    <th>Start time</th>
    <th>End time</th>
		<th>Instructor</th>
		<% unless @current_user.student? %>
			<th>Registration</th>
		<% end %>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @timeslots.each do |timeslot| %>
  <tr>
		<td><%= timeslot.date %></td>
    <td><%= timeslot.start_time_string %></td>
    <td><%= timeslot.end_time_string %></td>
		<td><%= link_to timeslot.instructor.full_name, timeslot.instructor %></td>
		<% unless @current_user.student? %>
			<td><%= link_to timeslot.active_registration.student.full_name, timeslot_registration_path(timeslot, timeslot.active_registration) if timeslot.registered? %></td>
		<% end %>
		<% if @current_user.student? %>
		<td><%= link_to 'Register', timeslot_registrations_path(timeslot), method: :post %></td>
		<% end %>
    <td><%= link_to 'Show', timeslot %></td>
		<% unless @current_user.student? %>
			<td>
			<% unless timeslot.registered? %>
    		<%= link_to 'Destroy', timeslot, confirm: 'Are you sure?', method: :delete %>
			<% else %>
				<%= link_to 'Cancel', new_timeslot_cancellation_report_url(timeslot) %>
			<% end %>
      <% if !timeslot.active? && timeslot.unresolved? %>
        <%= link_to 'Add lesson', new_timeslot_driving_lesson_url(timeslot) %>
      <% end %>
			</td>
		<% end %>
  </tr>
<% end %>
</table>

<br />

<% unless @current_user.student? %>
  <%= link_to 'New Timeslot', new_timeslot_path %>
<% end %>
